package cn.com.demo.autoconfigure;

import cn.com.demo.autoconfigure.properties.DemoProperties;
import cn.com.demo.autoconfigure.service.DemoService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(DemoProperties.class)
public class DemoAutoConfigure {
    /**属性自动从Springboot配置文件装配，DemoProperties里声明前缀*/
    private DemoProperties demoProperties;
    /*public DemoAutoConfigure(){
        System.out.println("init no patam ");
    }*/
    public DemoAutoConfigure(DemoProperties demoProperties) {
        this.demoProperties = demoProperties;
    }

    /**
     * 自定义Bean以供外部使用
     * @return
     */
    @Bean
    @ConditionalOnMissingBean
    public DemoService demoService(){
        return new DemoService(demoProperties);
    }
}
